<?php
<<<<<<< HEAD
namespace app\index\controller;

use think\Url;

class Index
{
    public function index()
    {
        return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一剑 - 为API开发设计的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_bd568ce7058a1091"></thinkad>';
    }

    // 生成对应的URL
    public function url()
    {
        echo Url::build('index/index/user',' id=5');
        echo '<br>';
        echo Url::build('index/index/user');
        // 助手函数
        echo '<br>';
        echo url('index/blog/index','id=66');
        echo '<br>';
        echo Url::build('index/blog/article',['year'=>'2018','month'=>'01']);

    }

=======

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
class Index extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
       
        $list =  Db::table('carousel')
        ->alias('c')
        ->join('article a','c.aid = a.aid')
        ->join('images i','a.aid = i.aid')
        ->where('c.display = 1')
        ->select();

       $article = Db::table('article a')
       ->join('images i','a.aid = i.aid')
       ->join('user_self u','u.uid = a.uid')
       // ->join('discuss d','a.aid = d.aid')
       ->select();

       $discuss = Db::table('discuss d')
       ->join('article a','a.aid = d.aid')
       ->where('a.aid = d.aid')
       ->count();
        // var_dump($discuss);die;

 
         return view('index', [
            'article' => $article,
            'discuss' => $discuss,
            'list' => $list
        ]);
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {

        $list = Db::table('user_func')->field('tel')->select();
        $p = $request->post();
       foreach ($list as $k => $v) {
           $tel[]= $v['tel'];
       }
        foreach ($tel as $key => $v) {
            if ($v == $p['tel']) {
                return $this->success('此号码已注册');            
            }
        } 
        
        $data = ['tel' => $p['tel'], 'pwd' => $p['pwd'],'regtime'=>$p['time']];
        
        $list = Db::name('user_func')->data($data)->insert();
        if ($list > 0) {
           return $this->success('添加成功', url('index/index/index'));
        } else {
            return $this->success('添加失败(ノ°ο°)ノ高能预警 ');
        }
    }
    
    /**
     * 登录
     * @return [type] [description]
     */
    public function sign(Request $request){
             $p = $request->post();

             $data = ['tel' => $p['phone'], 'pwd' => $p['pwd']];

             $list = Db::table('user_func')->where('tel',$p['phone'])->find();

             $name = Db::table('user_self')->where('uid',$list['uid'])->find();
             // var_dump($name['nickname']);die;

             $tel = $list['tel'];
             $pwd = $list['pwd'];
             if ($p['phone'] !== $tel) {
                return $this->error('账号错误');
             } elseif ($p['pwd'] !== $pwd) {
                return $this->error('密码错误');

             } {
               session('tel',$tel);
               session('name',$name['nickname']);

               return $this->success('登录成功');
             }
    }

    /**
     * 退出登录
     * @return [type] [description]
     */
    public function log(){
        session('tel', null);
        session('name', null);
        $this->success('退出成功',url('index/Index/index'));
    }


    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
     
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }


    // public function carousle(){
    //       $list =  Db::table('carousel')
    //         ->alias('c')
    //         ->join('article a','c.aid = a.aid')
    //         ->select();
    //         var_dump($list);die
    // }
>>>>>>> f7ff0be6c30987dc092991254b9df280e9ffeef4
}
